﻿using System;
using System.Collections.Generic;
using System.Data.Linq.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TracNghiemV1.Database;

namespace TracNghiemV1.DAO
{
    class QuestionSolutionDao
    {
        private static TestDataDataContext m_dataContext = null;

        public static void AddQuestionSlolution(QUESTION_SOLUTION newQuestionSolution)
        {

            m_dataContext = DataContextDao.GetInstance();

            m_dataContext.QUESTION_SOLUTIONs.InsertOnSubmit(newQuestionSolution);
            m_dataContext.SubmitChanges();
        }

        public static void DeleteQuestionSolution(int questionId)
        {
            m_dataContext = DataContextDao.GetInstance();

            IList<QUESTION_SOLUTION> lstQS = FindQuestionSolutionListWithQuestionId(questionId);

            foreach (QUESTION_SOLUTION qt in lstQS)
            {
                m_dataContext.QUESTION_SOLUTIONs.DeleteOnSubmit(qt);
            }
            
           
            m_dataContext.SubmitChanges();
        }

        public static IList<QUESTION_SOLUTION> FindQuestionSolutionListWithQuestionId(int questionId)
        {
            m_dataContext = DataContextDao.GetInstance();

            var questionSolutions = from p in m_dataContext.QUESTION_SOLUTIONs
                          where p.QUESTION_ID == questionId
                          select p;
            return questionSolutions.ToList();
        }

        
    }
}
